package ServiceImpl;

import java.util.List;

import Bean.Info;
import Dao.InfoDao;
import Service.InfoService;

public class InfoServiceImpl implements InfoService {

	@Override
	public boolean insert(String car_id, String in_info, String out_info) {
		// 进入 就null 离开
		// 离开 就null 进入
		InfoDao infoDao = new InfoDao();
		Info info = new Info();
		try {
			info.setCar_id(car_id);
			info.setIn_info(in_info);
			info.setOut_info(out_info);
			System.out.println("before checked!");
			Info tmp = infoDao.selectByCarId(car_id);//here
			System.out.println("after checked!");
			if(tmp != null) {
				System.out.println("before if!");
				if(tmp.getIn_info() != null && in_info != null) {
					return false;
				} else if(tmp.getOut_info() != null && out_info != null) {
					return false;
				}
				System.out.println("after if!");
				infoDao.update(info);
				System.out.println("after update!");
			} else {
				infoDao.insert(info);
			}
			return true;
		} catch(Exception e) {
			System.out.println("exception!");
			return false;
		}
	}

	@Override
	public Info selectAllInfoByCarId(String car_id) {
		InfoDao infoDao = new InfoDao();
		try {
			return infoDao.selectByCarId(car_id);
		} catch(Exception e) {
			return null;
		}
	}

	@Override
	public boolean dropByCarId(String car_id) {
		InfoDao infoDao = new InfoDao();
		try {
			infoDao.dropByCarid(car_id);
			return true;
		} catch(Exception e) {
			return false;
		}
	}
	
}
